package models

import (
	"github.com/astaxie/beego/orm"
)

type Info struct {
	Id         int
	Title      string
	Author     string
	Prose      string
	Desc       string
	Content    string
	Image      string
	Hits       int
	OrderId    int
	ClassId    int
	CreateTime string
	UpdateTime string
}

func (i *Info) TableName() string {
	return "info"
}

// InsertInfo 插入数据
func InsertInfo(infoData Info) int64 {
	o := orm.NewOrm()

	id, err := o.Insert(&infoData)
	if err != nil {
		panic(err)
	}

	return id
}

func GetList(offset int, key string) []Info {
	list := make([]Info, 0)

	query := orm.NewOrm().QueryTable(new(Info))
	fields := []string{"id", "title", "author", "image"}
	query.Offset(offset*20).Limit(20).All(&list, fields...)

	return list
}
